'use strict';
//佣金明细
import React,{Component} from 'react';
import Header from '../../common/header';
import * as URLconstant from '../../constant/URLconstant'
import Util from '../../common/util';
import {
    View,
    Text,
    TouchableOpacity,
    Image,
    StyleSheet,
    ScrollView
} from 'react-native';
export default class commissionList extends Component{
    // 构造
      constructor(props) {
        super(props);
        // 初始状态
        this.state = {
            incomeList:null
        };
      }

    componentDidMount() {
        this.getList()
    }

      getList(){
          let url = URLconstant.COMMISSION_LIST
          let datakey=[]
          datakey['user_id']=this.props.user_id
          datakey['type']=this.props.type
          Util.get(url,datakey,this.getListSuc.bind(this),this.errorCallback.bind(this))
      }

    getListSuc(datas){
        if(datas.status==0){
            this.setState({
                incomeList:datas.data.list
            })
        }else{
            this.setState({
                incomeList:[]
            })
        }
    }
    errorCallback(err){

    }

    backTypeTxt(type){
          let txt = ''
        switch(parseInt(type)){
            case 0:
                txt='粉丝层'
                break
            case 1:
                txt='代理直推返利'
                break
            case 3:
                txt='代理三级返利'
                break
            case 4:
                txt='代理升级奖励'
                break
            case 5:
                txt='代理团队奖'
                break
            case 6:
                txt='服务券佣金'
                break
            case 7:
                txt='店员服务提成奖励'
                break
            case 8:
                txt='店主渠道提成奖励'
                break
            case 9:
                txt='代理商同级返利'
                break
            case 10:
                txt='代理商销售提成'
                break
            case 11:
                txt='代理商推荐返利'
                break
            case 12:
                txt='代理商团队奖励'
                break
            case 13:
                txt='佣金转积分'
                break
            case 14:
                txt='配送佣金'
                break
        }
        return txt
    }

    backOrderTxt(order_status){
          let txt = ''
          switch (parseInt(order_status)){
              case 30:
                  txt='已发货'
                  break
              case 20:
                  txt='待发货'
                  break
              case 38:
                  txt='已收货'
                  break
              case 40:
                  txt='交易成功'
                  break
              case 31:
                  txt='已申请退货'
                  break
              case 32:
                  txt='审核通过'
                  break
              case 33:
                  txt='退换货待发货'
                  break
              case 34:
                  txt='退换货已发货'
                  break
              case 35:
                  txt='审核中'
                  break
              case 36:
                  txt='已退款'
                  break
              case 37:
                  txt='审核不通过'
                  break
              case 0:
                  txt="订单已取消"
                  break
          }
          return txt
    }


      render(){
          let incomeList = this.state.incomeList
          return(
              <View style={{flex:1,backgroundColor:"#f0f0f0"}}>
                  <Header navigator={this.props.navigator} initObj={{ title: '佣金明细',id:2}}/>
                  {
                      incomeList==null?
                          <View style={{flex:1}}>
                              {Util.loading()}
                          </View>:
                          <View style={{flex:1}}>
                              {
                                  this.props.type=='yes'?
                                  <View style={styles.no_finish_view}>
                                      <Text style={{fontSize:12,color:"#278826"}}> 未完成收益是指还在“待发货、待收货、7天退换货期”内的订单产生的佣金收益。该收益会在订单完成后进入可提现收益中。如果该订单退货，相应佣金会被划出。 </Text>
                                  </View>
                                      :
                                      null
                              }
                              {
                              incomeList.length==0?
                                  <View style={{flex:1, alignItems:'center',justifyContent:'center'}}>
                                      <Text>没有佣金明细</Text>
                                  </View>
                                  :
                                  <ScrollView style={{flex:1}}>
                                      {
                                          incomeList.map((item,index)=>{
                                              return(
                                                  <View style={styles.income_item} key={index}>
                                                      <View style={styles.txt_view}>
                                                          <Text style={styles.item_txt}>订单号:{item.order_sn}</Text>
                                                      </View>
                                                      <View style={styles.txt_view}>
                                                          <Text style={styles.item_txt}>订单金额:{item.order_amount}</Text>
                                                      </View>
                                                      <View style={styles.txt_view}>
                                                          <Text style={styles.item_txt}>付款时间:{item.add_time}</Text>
                                                      </View>
                                                      <View style={styles.txt_view}>
                                                          <Text style={styles.item_txt}>佣金收益:</Text>
                                                          {
                                                              item.order_status!=0?
                                                                  <Text style={{fontSize:12,color:"#ff5000",marginLeft:5}}>¥{item.income}</Text>
                                                                    :
                                                                  <Text style={{fontSize:12,color:"#969696",marginLeft:5,textDecorationLine:'line-through'}}>¥{item.income}</Text>
                                                          }
                                                      </View>
                                                      <View style={styles.txt_view}>
                                                          <Text style={styles.item_txt}>下单昵称:{item.buyer_name}</Text>
                                                      </View>
                                                      <View style={styles.txt_view}>
                                                          <Text style={styles.item_txt}>佣金类型:{this.backTypeTxt(item.type)}</Text>
                                                      </View>
                                                      <Text style={styles.back_txt}>{this.backOrderTxt(item.order_status)}</Text>
                                                  </View>
                                              )
                                          })
                                      }
                                  </ScrollView>
                              }
                          </View>

                  }
              </View>
          )
      }
}
var styles = StyleSheet.create({
    income_item:{
        paddingHorizontal:10,
        paddingVertical:8,
        backgroundColor:"#fff",
        marginBottom:10
    },
    txt_view:{
        height:20,
        flexDirection:'row',
        alignItems:'center'
    },
    item_txt:{
        fontSize:12,
        color:"#333"
    },
    back_txt:{
        fontSize:15,
        color:"#000",
        position:'absolute',
        top:10,
        right:10
    },
    no_finish_view:{
        padding:10,
    }
})